import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const $time 	= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '医院名称',		name: 'hosp_id',		type:'select' },
			{ label: '生成时间',		names: ['start_date','end_date'],		name:'jz-time', 	type:'date-range', 	loading:true },
		],
	}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['1-now']()
			this.resetModel = { start_date: arr[0], end_date: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 医院名称
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'bs-hospital/select' }) )
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'barcode/usage')
	controls = ()=> []
	
	// 表单
	cols = [
		{ title: '医院名称', dataIndex: 'hosp_name', 		width:150 },
		{ title: '回收', 	dataIndex: 'use_num', 		...$fn.table.num },
		{ title: '作废', 	dataIndex: 'invalid_num', 		...$fn.table.num },
		{ title: '生成', 	dataIndex: 'total', 			...$fn.table.num	 },
	]
	
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this, {timeStr:'1-now'}) }
				{/* 表格 */}
				{ Table.call(this, {idStr: 'id', type: -1, isInit: window.isInit} ) }
			</>
		)
	}
}

export default Index